home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / apps / math / lpsolves.zoo / dual.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-07  |  2.9 KB  |  162 lines

  1. #include "defines.h"
  2. #include "globals.h"
  3.  
  4. #ifdef alliant
  5. #pragma global safe (Eta_rownr, Eta_value)
  6. #pragma global assoc
  7. #endif
  8.  
  9. void  rowdual(int *rownr)
  10. {
  11.   int    i;
  12.   double f, g, minrhs;
  13.   short  artifs;
  14.  
  15. #ifdef alliant
  16. #pragma safe (Rhs, Upbo, Bas)
  17. #endif
  18.   
  19.   if (Verbose)
  20.     printf("rowdual\n");
  21.   (*rownr) = 0;
  22.   minrhs = -EPSB;
  23.   i = 0;
  24.   artifs = FALSE;
  25.   while (i < Rows && !artifs)
  26.     {
  27.       i++;
  28.       f = Upbo[Bas[i]];
  29.       if (f == 0 && Rhs[i] != 0)
  30.     {
  31.       artifs = TRUE;
  32.       (*rownr) = i;
  33.     }
  34.       else
  35.     {
  36.       if (Rhs[i] < f - Rhs[i])
  37.         g = Rhs[i];
  38.       else
  39.         g = f - Rhs[i];
  40.       if (g < minrhs)
  41.         {
  42.           minrhs = g;
  43.           (*rownr) = i;
  44.         }
  45.     }
  46.     }
  47. } /* rowdual */
  48.  
  49.  
  50. short  coldual(int *numeta,
  51.            int *rownr,
  52.            int *colnr,
  53.            short *minit,
  54.            double *prow,
  55.            double *drow)
  56. {
  57.   int    i, j, r, varnr;
  58.   double theta, quot, pivot, d, f, g;
  59.   
  60. #ifdef alliant
  61. #pragma safe (Rhs, Upbo, Bas, Cend, Endetacol, prow, drow, Basis, Lower)
  62. #endif
  63.  
  64.   if (Verbose)
  65.     printf("coldual\n");
  66.   if (!(*minit))
  67.     {
  68.       for (i = 0; i <= Rows; i++)
  69.     {
  70.       prow[i] = 0;
  71.       drow[i] = 0;
  72.     }
  73.       drow[0] = 1;
  74.       prow[(*rownr)] = 1;
  75.       for (i = (*numeta); i >= 1; i--)
  76.     {
  77.       d = 0;
  78.       f = 0;
  79.       r = Eta_rownr[Endetacol[i] - 1];
  80.       for (j = Endetacol[i - 1]; j < Endetacol[i]; j++)
  81.         {
  82.           /* this is where the program consumes most cpu time */
  83.           f = f + prow[Eta_rownr[j]] * Eta_value[j];
  84.           d = d + drow[Eta_rownr[j]] * Eta_value[j];
  85.         }
  86.       if (abs(f) < EPSEL)
  87.         prow[r] = 0;
  88.       else
  89.         prow[r] = f;
  90.       if (abs(d) < EPSEL)
  91.         drow[r] = 0;
  92.       else
  93.         drow[r] = d;
  94.     }
  95.       for (i = 1; i <= Columns; i++)
  96.     {
  97.       varnr = Rows + i;
  98.       if (!Basis[varnr])
  99.         {
  100.           d = -Extrad * drow[0];
  101.           f = 0;
  102.           for (j = Cend[i - 1]; j < Cend[i]; j++)
  103.         {
  104.           d += drow[Mat[j].rownr] * Mat[j].value;
  105.           f += prow[Mat[j].rownr] * Mat[j].value;
  106.         }
  107.           drow[varnr] = d;
  108.           prow[varnr] = f;
  109.         }
  110.     }
  111.  
  112. #ifdef alliant
  113. #pragma loop novector
  114. #endif
  115.       
  116.       for (i = 0; i <= Sum; i++)
  117.     {
  118.       if (abs(prow[i]) < EPSEL)
  119.         prow[i] = 0;
  120.       if (abs(drow[i]) < EPSD)
  121.         drow[i] = 0;
  122.     }
  123.     }
  124.   if (Rhs[(*rownr)] > Upbo[Bas[(*rownr)]])
  125.     g = -1;
  126.   else
  127.     g = 1;
  128.   pivot = 0;
  129.   (*colnr) = 0;
  130.   theta = INFINITE;
  131.   for (i = 1; i <= Sum; i++)
  132.     {
  133.       if (Lower[i])
  134.     d = prow[i] * g;
  135.       else
  136.     d = -prow[i] * g;
  137.       if (d < 0)
  138.     if (!Basis[i])
  139.       if (Upbo[i] > 0)
  140.         {
  141.           if (Lower[i])
  142.         quot = -drow[i] / (double) d;
  143.           else
  144.         quot = drow[i] / (double) d;
  145.           if (quot < theta)
  146.         {
  147.           theta = quot;
  148.           pivot = d;
  149.           (*colnr) = i;
  150.         }
  151.           else
  152.         if (quot == theta)
  153.           if (abs(d) > abs(pivot))
  154.             {
  155.               pivot = d;
  156.               (*colnr) = i;
  157.             }
  158.         }
  159.     }
  160.   return ((*colnr) > 0);
  161. } /* coldual */
  162.